package gamesys.games.particlesystem.core {
	import gamesys.games.particlesystem.AbstractTest;

	import particlesystem.core.ParticleCanvas;
	import particlesystem.core.ParticleEffect;
	import particlesystem.core.ParticleSettings;
	import particlesystem.effects.DecayEffect;
	import particlesystem.effects.GravityEffect;
	import particlesystem.effects.LifeEffect;
	import particlesystem.effects.VelocityEffect;
	import particlesystem.graphics.BitmapAnimationFactory;
	import particlesystem.utils.Range;

	import flash.display.Sprite;
	import flash.events.Event;
	import flash.filters.GlowFilter;
	import flash.geom.Rectangle;

	/**
	 * @author robertthurston
	 */
	[SWF (width="577", height="469", frameRate="30", backgroundColor="0x222222")]

	public class ParticleEffectTest3 extends AbstractTest {

		private var particleEffect : ParticleEffect;
		private var particleCanvas : ParticleCanvas;
		private var particleSettings : ParticleSettings;
		private var emitter : Sprite;
		private var bitmapAnimationFactory : BitmapAnimationFactory;
		private var particleSettings2 : ParticleSettings;
		private var particleEffect2 : ParticleEffect;

		override protected function init() : void {
			emitter = new Sprite();
			emitter.graphics.beginFill(0xFF0000);
			emitter.graphics.drawCircle(5, 5, 5);
			emitter.x = 0;
			emitter.y = 200;
			addChild(emitter);
			
			bitmapAnimationFactory = new BitmapAnimationFactory();
			
			particleCanvas = new ParticleCanvas(577, 469);
			particleCanvas.filters = [new GlowFilter(0xFFFFFF, 1, 6, 6, 2)];
			
			particleSettings = new ParticleSettings();
			particleSettings.startBounds = new Rectangle(0, 0, 577, 1);
			particleSettings.startDelayRange = new Range(0, 0);
			particleSettings.reSpawn = false;
			particleSettings.emitter = emitter;
			particleSettings.bitmapAnimationParticles = [bitmapAnimationFactory.getBitmapAnimation("FairyDust1")];
			
			particleEffect = new ParticleEffect(particleSettings, particleCanvas);
			particleEffect.addEffect(new LifeEffect(15, 15, 10));
			particleEffect.addEffect(new VelocityEffect(1, 20, 0, 0));
			particleEffect.addEffect(new GravityEffect(0, 0));
			particleEffect.addEffect(new DecayEffect(.75, .75));
			
			particleSettings2 = new ParticleSettings();
			particleSettings2.startBounds = new Rectangle(0, 0, 577, 1);
			particleSettings2.startDelayRange = new Range(0, 0);
			particleSettings2.reSpawn = false;
			particleSettings2.emitter = emitter;
			particleSettings2.bitmapAnimationParticles = [bitmapAnimationFactory.getBitmapAnimation("FairyDust2")];
			
			particleEffect2 = new ParticleEffect(particleSettings2, particleCanvas);
			particleEffect2.addEffect(new LifeEffect(30, 30, 10));
			particleEffect2.addEffect(new VelocityEffect(1, 10, 0, 0));
			particleEffect2.addEffect(new GravityEffect(0, 0));
			particleEffect2.addEffect(new DecayEffect(.95, .95));
			
			addChild(particleCanvas);
			
			addEventListener(Event.ENTER_FRAME, onEnterFrame);
		}

		private function onEnterFrame(event : Event) : void {
			particleCanvas.clear();
			
			particleEffect.addParticles(50);
			particleEffect.update();
			
			particleEffect2.addParticles(50);
			particleEffect2.update();
		}
	}
}
